package office.service.hr.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import office.action.hr.form.RecruitRequirementForm;
import office.bo.hr.IRecruitRequirement;
import office.bo.hr.impl.RecruitRequirement;
import office.domainset.BizDomainProviderSetImpl;
import office.service.hr.IRecruitRequirementService;
import platform.common.exception.BusinessException;
import platform.common.service.impl.BaseBizServiceImpl;

public class RecruitRequirementServiceImpl extends BaseBizServiceImpl implements IRecruitRequirementService{
	
	/**
	 * 获取招聘需求信息
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public List getRecruitRequirementList(String deptId,boolean all) throws BusinessException{
		List listData = new ArrayList() ;
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			if(all){
				listData = domainProviderSetImpl.getDao().findByHqlNameAndDomian(domainProviderSetImpl.getRecruitRequirementDP(), "findAll", new HashMap());
			}else{
				Map<String,Object> map = new HashMap<String,Object>();
				map.put("deptId",deptId);
				listData = domainProviderSetImpl.getDao().findByHqlNameAndDomian(domainProviderSetImpl.getRecruitRequirementDP(), "findByDept", map);
			}
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("获取招聘信息失败!", e);
		}
		return listData;
	}
	
	/**
	 * 编辑招聘需求
	 * @throws BusinessException
	 */
	public void editRecruitRequirement(RecruitRequirementForm objctForm)throws BusinessException{
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			RecruitRequirement bo = null;
			if(null==objctForm.getId() || ("").equals(objctForm.getId())){
				bo = (RecruitRequirement)domainProviderSetImpl.getRecruitRequirementDP().newEmptyObj();
			}else{
				bo = (RecruitRequirement)domainProviderSetImpl.getDao().findByIdAndDomain(domainProviderSetImpl.getRecruitRequirementDP(), objctForm.getId());
			}
			bo =(RecruitRequirement) objctForm.copyPropertiesToBO(bo);
			if(null==bo.getId() || ("").equals(bo.getId())){
				bo.generatorUUID();
				bo.setDeptId(objctForm.getDeptId());
			}
			//验证是否存在重复记录
			bo.store(domainProviderSet);
			
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("编辑招聘信息失败!", e);
		}
	}
	
	/**
	 * 根据id获取对象
	 * @param id
	 * @return
	 * @throws BusinessException
	 */
	public RecruitRequirementForm getById(String id)throws BusinessException{
		RecruitRequirementForm form = new RecruitRequirementForm();
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IRecruitRequirement bo = (IRecruitRequirement)domainProviderSetImpl.getDao().findByIdAndDomain(domainProviderSetImpl.getRecruitRequirementDP(), id);
			form.copyPropertiesFromBO(bo);
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("根据id获取招聘信息对象失败!", e);
		}
		return form;
	}
	
	/**
	 * 根据id删除对象
	 * @param id
	 * @throws BusinessException
	 */
	public void deleteById(String id)throws BusinessException{
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			domainProviderSetImpl.getDao().deleteById(domainProviderSetImpl.getRecruitRequirementDP(), id);
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("根据id获取招聘信息对象失败!", e);
		}
	}
	
	

}
